<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" />
    <script src="js/jquery.min.js"></script>
    <script src="js/layer-v3.1.1/layer/layer.js"></script>
    <script src="js/demo.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</head>
<script src="assets/js/lib/jquery.min.js"></script>
<script type="text/javascript">
    var teacherdelete = function (){
        var ID=$("#ID").val();
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/UserDelete?userid="'+ID+'"',
            dataType: 'json',
            data: {},
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                }
                window.location="<%=request.getContextPath() %>/manage/allTeacher.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
            },
        });
    }
    var cancel=function(){
        layer.close(index);
        $("#deleteBox").css("display","none");
    }
    var teachermodify = function (){
        var teacherid=$.trim($("#InputTeacherId").val());
        var teachername=$.trim($("#InputTeachername").val());
        var pwd=$.trim($("#InputTeacherPwd").val());
        var teacherphoto=$.trim($("#InputTeacherPhoto").val());
        var teacherintroduction=$.trim($("#InputTeacherIntroduction").val());
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/TeacherModify',
            dataType: 'json',
            data: JSON.stringify({
                teacherid: teacherid,
                teachername: teachername,
                pwd: pwd,
                teacherphoto: teacherphoto,
                teacherintroduction: teacherintroduction,
            }),
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                    window.alert('已提交执行');
                }
                window.location="<%=request.getContextPath() %>/manage/allTeacher.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#loginBox").css("display","none");
            },
        });
    }
    var teacheradd = function (){
        var teacherid=$.trim($("#AddTeacherid").val());
        var teachername=$.trim($("#AddTeachername").val());
        var pwd=$.trim($("#AddTeacherPwd").val());
        var teacherphoto=$.trim($("#AddTeacherPhoto").val());
        var teacherintroduction=$.trim($("#AddTeacherIntroduction").val());
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/TeacherAdd',
            dataType: 'json',
            data: JSON.stringify({
                teacherid: teacherid,
                teachername: teachername,
                pwd: pwd,
                teacherphoto: teacherphoto,
                teacherintroduction: teacherintroduction,
            }),
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                    window.alert('已提交执行');
                }
                window.location="<%=request.getContextPath() %>/manage/allTeacher.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#addBox").css("display","none");
            },
        });
    }
    var searchteacher=function (){
        var keyword=$.trim($("#key").val());
        $.ajax({
            url:"<%=request.getContextPath()%>/ShowTeacherByKeyword?keyword='"+keyword+"'",
            type:"GET",
            dataType:"json",
            success: function(data) {
                var item=data;
                var html = "";
                for(var i=0;i<item.length;i++){
                    var teacherid=item[i].teacher_id;
                    var teachername=item[i].teacher_name;
                    var teacherintroduction=item[i].teacher_introduction;
                    var teacherphoto=item[i].teacher_photo;
                    var pwd=item[i].pwd;
                    html += '<tr><td id="teacherid">' + item[i].teacher_id + '</td><td id="teachername">'
                        + teachername+ '</td><td id="pwd">'
                        + pwd+ '</td><td id="teacherintroduction">'
                        + teacherintroduction + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowTeacherText(\''+teacherid+'\',\''+teachername+'\',\''+pwd+'\',\''+teacherintroduction+'\',\''+teacherphoto+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+teacherid+'\')" >删除</a></td></tr>';
                }
                $("#teacherlist").empty();
                $("#teacherlist").append(html);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            },
        })
    }
    window.onload=function tryapitest(){
        $.ajax({
            url:"<%=request.getContextPath()%>/ShowTeacher",
            type:"GET",
            dataType:"json",
            success: function(data) {
                var item=data;
                var html = "";
                for(var i=0;i<item.length;i++){
                    var teacherid=item[i].teacher_id;
                    var teachername=item[i].teacher_name;
                    var teacherintroduction=item[i].teacher_introduction;
                    var teacherphoto=item[i].teacher_photo;
                    var pwd=item[i].pwd;
                    html += '<tr><td id="teacherid">' + item[i].teacher_id + '</td><td id="teachername">'
                        + teachername+ '</td><td id="pwd">'
                        + pwd+ '</td><td id="teacherintroduction">'
                        + teacherintroduction + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowTeacherText(\''+teacherid+'\',\''+teachername+'\',\''+pwd+'\',\''+teacherintroduction+'\',\''+teacherphoto+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+teacherid+'\')" >删除</a></td></tr>';
                }
                $("#teacherlist").append(html);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            },
        })
    }

</script>
<body>
<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <ul>
                <div class="logo"><a href="index.jsp"><span>教务管理系统后台</span></a></div>
                <li class="label">Main</li>
                <%
                    if(request.getSession().getAttribute("identity")!=null){
                        int identity=(int)request.getSession().getAttribute("identity");
                        if(identity==3){
                %>
                <li><a class="sidebar-sub-toggle"><i class="ti-home"></i>用户管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allUser.jsp">查看所有用户</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>教师管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allTeacher.jsp">查看所有教师</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-home"></i>场地管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allPlace.jsp">查看所有场地</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>班级管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allClass.jsp">查看所有班级</a></li>
                    </ul>
                </li><%
            }
            else{%>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>课程管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allCourse.jsp">查看所有课程</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>上课管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allStudent.jsp">查看签到情况</a></li>
                    </ul>
                </li><%
                }
            }
            else{
            %>
                <a href="<%=request.getContextPath()%>/enter">请登录</a>
                <a href="<%=request.getContextPath()%>/register">免费注册</a><%
                }
            %>

            </ul>
        </div>
    </div>
</div>
<div class="header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="dropdown dib">
                    <div class="header-icon" data-toggle="dropdown">
								<span class="user-avatar"><%=request.getSession().getAttribute("userid") %>
                                    <i class="ti-angle-down f-s-10"></i>
                                </span>
                        <div class="drop-down dropdown-profile dropdown-menu dropdown-menu-right">
                            <div class="dropdown-content-body">
                                <ul>
                                    <li>
                                        <a href="#">
                                            <i class="ti-settings"></i>
                                            <span>Setting</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="<%=request.getContextPath() %>/exit">
                                            <i class="ti-power-off"></i>
                                            <span>Logout</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>Hello, <span>There are all teachers.</span></h1>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div>
            <div class="card">
                <div class="card-title pr">
                    <h4>所有查找结果</h4>
                </div>
                <div>
                    <input type="text" placeholder="teacherid" name="key" id="key">
                    <button id="btn" type="submit" onclick="searchteacher()">搜索</button>
                    <button id="add_btn" type="primary" onclick="AddTeacherText()">添加</button>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table student-data-table m-t-20">
                            <thead>
                            <tr>
                                <th>教师ID</th>
                                <th>教师姓名</th>
                                <th>教师密码</th>
                                <th>教师简介</th>
                                <th>编辑</th>
                                <th>删除</th>
                            </tr>
                            </thead>
                            <tbody id="teacherlist">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="loginBox">
    <div class="login-item"><input  type="hidden" id="InputTeacherId"/></div>
    <div class="login-item">姓名：<input  type="text" id="InputTeachername" placeholder="姓名" /></div>
    <div class="login-item">密码：<input  type="text" id="InputTeacherPwd" placeholder="密码"/></div>
    <div class="login-item">照片地址：<input  type="text" id="InputTeacherPhoto" placeholder="照片地址"/></div>
    <div class="login-item">简介：<input  type="text" id="InputTeacherIntroduction" placeholder="简介"/></div>
    <div class="login-item"><a href="javascript:;" onclick="teachermodify()">修改</a></div>
</div>
<div id="addBox">
    <div class="login-item">用户名：<input  type="text" id="AddTeacherid" placeholder="用户名"/></div>
    <div class="login-item">姓名：<input  type="text" id="AddTeachername" placeholder="姓名" /></div>
    <div class="login-item">密码：<input  type="text" id="AddTeacherPwd" placeholder="密码"/></div>
    <div class="login-item">照片地址：<input  type="text" id="AddTeacherPhoto" placeholder="照片地址"/></div>
    <div class="login-item">简介：<input  type="text" id="AddTeacherIntroduction" placeholder="简介"/></div>
    <div class="login-item"><a href="javascript:;" onclick="teacheradd()">添加</a></div>
</div>
<div id="deleteBox">
    <p>确定要删除该教师吗？</p>
    <div class="login-item"><input type="hidden" id="ID" /></div>
    <div class="delete-item div-inline"><a href="javascript:;" onclick="teacherdelete()">确认</a></div>
    <div class="delete-item div-inline"><a href="javascript:;" onclick="cancel()">取消</a></div>
</div>
<script src="assets/js/lib/jquery.min.js"></script>
<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="assets/js/lib/menubar/sidebar.js"></script>
<script src="assets/js/lib/preloader/pace.min.js"></script>
<script src="assets/js/lib/bootstrap.min.js"></script>
<script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
<script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</body>
</html>